using BusinessLogic.BusinessEntity.Interfaces;
using BusinessLogic.Connectivity.Interfaces;
using NHibernate;

namespace DataAccess.Services
{
	public abstract class GatewayBase<T> : IGatewayBase<T> where T: class, IIdentifiedEntity, new()
	{
		protected readonly DataControl.DataControl dataControl;

		public DataControl.DataControl DataControl
		{
			get { return dataControl; }
		}

		protected GatewayBase(ISession session)
		{
			dataControl = new DataControl.DataControl(session);
		}

		public T GetById(int id)
		{
			return DataControl.LoadItemById<T>(id);
		}

		public void Delete(T obj)
		{
			DataControl.Delete(obj);
		}

		public void Delete(int id)
		{
			Delete(new T {ID = id});
		}

		public int Insert(T obj)
		{
			return DataControl.Add(obj);
		}

		public void Update(T obj)
		{
			DataControl.Edit(obj);
		}
	}
}